package com.example.datn.manager;

import java.util.ArrayList;

import com.example.datn.objects.AlbumObject;
import com.example.datn.objects.SongObject;

public class AlbumManager {
	public static final AlbumManager INSTANCE = new AlbumManager();
	AlbumObject currentAlbum; 
	ArrayList<AlbumObject> ListAlbum = new ArrayList<AlbumObject>();
	ArrayList<SongObject> listSongOfAlbum = new ArrayList<SongObject>();
	private int currentSongPosition = 0;
	
	public AlbumObject getCurrentAlbum() {
		return currentAlbum;
	}

	public void initListSong(String _albumId){
		listSongOfAlbum.clear();
		ArrayList<SongObject> listAllSong = SongManager.getInstance().getListSong();		
		for (SongObject song : listAllSong) {
			if(song.albumId.equals(_albumId))
				listSongOfAlbum.add(song);
		}		
	}
	
	public ArrayList<SongObject> getListSongOfAlbum(){		
		return listSongOfAlbum;
	}
		
	public SongObject getNextSongOfAlbum(){
		if(currentSongPosition == listSongOfAlbum.size()-1)
			currentSongPosition = 0;
		else ++currentSongPosition;
		return listSongOfAlbum.get(currentSongPosition);
	}
	
	public SongObject getPreviousSongOfAlbum(){
		if(currentSongPosition == 0)
			currentSongPosition = listSongOfAlbum.size()-1;
		else --currentSongPosition;
		return listSongOfAlbum.get(currentSongPosition);
	}
	
	public SongObject getCurrentSong(){
		return listSongOfAlbum.get(currentSongPosition);
	}
	
	public ArrayList<AlbumObject> getListAlbum() {
		return ListAlbum;
	}

	public void setListAlbum(ArrayList<AlbumObject> listAlbum) {
		ListAlbum = listAlbum;
	}
	
	public void setCurrentAlbum(AlbumObject currentAlbum) {
		this.currentAlbum = currentAlbum;
	}

	public static AlbumManager getInstance() {
		return INSTANCE;
	}
	
	public void release(){
		this.ListAlbum.clear();
		currentAlbum = null;		
	}
		
}
